<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>体育与健康课程管理系统</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/css/main.css"/>
    <link href="${pageContext.request.contextPath}/public/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/libs/modernizr.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/jquery-3.2.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/public/js/layer/layer.js"></script>
    <script src="${pageContext.request.contextPath}/public/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container clearfix" style="width:100%">
    <!--/sidebar-->
    <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list" style="background:#fff; border:0px"><i class="icon-font"></i>修改系统基本参数</div>
        </div>
        <div class="result-wrap">
            <div class="result-title">
                <div class="result-list">
                    <a href="javascript:;" data-toggle="modal" data-target="#myModal" >考试周管理</a>
                </div>
            </div>
            <div class="result-content">
                <form  id="myform">
                    <table class="insert-tab" width="100%">
                        <tbody>   
                        <c:forEach items="${data }" var="v">
                            <tr>
                                <th><i class="require-red">*</i>${v.systemConfigComment }：</th>
                                <td>
                                    <input class="common-text required" id="title" name="systemConfigValue" size="85" value="${v.systemConfigValue } " onchange="upd(${v.systemConfigId},this.value)" style="width:300px;height:32px" type="text">
                                </td>
                            </tr>
                            </c:forEach>
                        </tbody></table>
                </form>
            </div>
        </div>

    </div>
    <!--/main-->
</div>
<div  class="modal fade bs-example-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header" >
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    考试周管理
                </h4>
            </div>
            <div style="margin:10px 20px; border:none">
                <lable><i class="require-red">*</i>考试周名称：</lable> <input name="systemExamWeeklyName"  placeholder="请输入考试周名称" class="common-text"  style="height:30px;width:120px"  />
                <lable><i class="require-red">*</i>所属考试类型：</lable>
                <select name="systemExamWeeklyType">
                    <option value="技能考试一">技能考试一</option>
                    <option value="技能考试二">技能考试二</option>
                    <option value="体能考试">体能考试</option>
                    <option value="体育知识考试">体育知识考试</option>
                </select>
                <lable><i class="require-red">*</i>所属学期：</lable>
                <select name="systemYearId" id="getyear">

                </select>
                <input class="btn btn-primary" name="sub" value="添加" type="button" onclick="addwee()"  style="margin-left:15px;width:80px">

                <div style="margin-top:20px">
                    <table class="result-tab" width="100%" id="addto">
                        <tr>
                            <th>考试周ID</th>
                            <th>考试周名称</th>
                            <th>所属考试类型</th>
                            <th>所属学期</th>
                            <th>操作</th>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    关闭
                </button>
                <button type="button" class="btn btn-primary" data-dismiss="modal">
                    提交
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
<script type="text/javascript">
$(document).ready(function(){

    $.get("${pageContext.request.contextPath}/system/getYear.action",{},function(returndata){
        for(var i=0;i<returndata.length;i++){
            $("#getyear").append("<option value='"+returndata[i].systemYearId+"'>"+returndata[i].systemYearName+"</option>");
        }
    });
    $.get("${pageContext.request.contextPath}/getweek.action",{},function(returndata){
    	if(returndata.code==1){
    		var id;
    		var name;
    		var type;
            var systemYearName;
    		for(var i=0;i<returndata.data.data.length;i++){
    			id=returndata.data.data[i].systemExamWeeklyId;
    			name=returndata.data.data[i].systemExamWeeklyName;
    			type=returndata.data.data[i].systemExamWeeklyType;
                systemYearName=returndata.data.data[i].systemYear.systemYearName;
    			$('#addto').append("<tr><td>"+id+"</td><td>"+name+"</td><td>"+type+"</td><td>"+systemYearName+"</td><td><button type='button' class='btn btn-danger' onclick='deleteweek("+id+","+i+")'>删除</button></td></tr>");
    		}
    		endi=returndata.data.data.length;
    	}
    });
})

function addwee(){
	var systemExamWeeklyName=$("input[name=systemExamWeeklyName]");
	var systemExamWeeklyType=$("select[name=systemExamWeeklyType]");
	var systemYearId=$("select[name=systemYearId]");
	if(systemExamWeeklyName.val()==""){
		layer.msg('考试周名称不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
		systemExamWeeklyName.focus();
        return ;
	}
	$.post("${pageContext.request.contextPath}/insertweek.action",{systemExamWeeklyName:systemExamWeeklyName.val(),systemExamWeeklyType:systemExamWeeklyType.val(),systemYearId:systemYearId.val()},function(returndata){
		if(returndata.code==1){
			var id=returndata.data.data.systemExamWeeklyId;
			var name=returndata.data.data.systemExamWeeklyName;
			var type=returndata.data.data.systemExamWeeklyType;
			var systemYearName=returndata.data.data.systemYear.systemYearName;
			$('#addto').append("<tr><td>"+id+"</td><td>"+name+"</td><td>"+type+"</td><td>"+systemYearName+"</td><td><button type='button' class='btn btn-danger' onclick='deleteweek("+id+","+endi+")'>删除</button></td></tr>");
            endi=endi+1;
		}else
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:1000}); 
	});
	
}

function deleteweek(id,index){
	$.get("${pageContext.request.contextPath}/deleteweek.action",{systemExamWeeklyId:id},function(returndata){
		if(returndata.code==1)
			$("#addto tr").eq(index+1).hide();	
		else
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:1000});
		
	});
}
function upd(id,value)
{
	$.post("${pageContext.request.contextPath}/system/updatesystem.action",{id:id,value:value},function(returndata){
		if(returndata.code==1)
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000});  
	});
}

</script>
</html>